<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>getSelection表示选择的范围</title>
  <!-- 返回一个 Selection 对象，表示用户选择的文本范围或光标的当前位置 -->
  <!-- https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getSelection -->
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
  </style>
</head>

<body>
</body>
<script>
  "use strict";
  function foo() {
    let selObj = window.getSelection();
    console.log(selObj);
    let selRange = selObj.getRangeAt(0);
  }
</script>

</html>